from .termination_condition_base import BaseTerminationCondition
from ..core.catalog import Catalog as c


class ExtremeState(BaseTerminationCondition):
    """ 
    极限状态
    如果飞机处于极限状态，则结束模拟
    """
    def __init__(self, config):
        super().__init__(config)
        
    def get_termination(self, task, env, agent_id, info={}):
        # 返回事件是否应终止。如果飞机处于极端状态，则结束模拟
        done = bool(env.agents[agent_id].get_property_value(c.detect_extreme_state))
        if done:
            env.agents[agent_id].crash()
            self.log(f'{agent_id} is on an extreme state! Total Steps={env.current_step}')
        success = False
        return done, success, info
        